﻿namespace UFIDA.U9.CUST.AITBarCodeRest
{
	using System;
	using System.Collections.Generic;
    using System.Text;
    using ufida.u9.ait.openapi.utils;
    using UFIDA.U9.CBO.Pub.Controller;
    using UFIDA.U9.CBO.SCM.Enums;
    using UFIDA.U9.CUST.AITBarCodeBE;
    using UFIDA.U9.CUST.AITBarCodeUseBE;
    using UFSoft.UBF.AopFrame;
    using UFSoft.UBF.Business;
    using UFSoft.UBF.Util.Context;
    using UFSoft.UBF.Util.Data;

    /// <summary>
    /// AITBarCodeUseSV partial 
    /// </summary>	
	public partial class AITBarCodeUseSV 
	{	
		internal BaseStrategy Select()
		{
			return new AITBarCodeUseSVImpementStrategy();	
		}		
	}
	
	#region  implement strategy	
	/// <summary>
	/// Impement Implement
	/// 
	/// </summary>	
	internal partial class AITBarCodeUseSVImpementStrategy : BaseStrategy
	{
		public AITBarCodeUseSVImpementStrategy() { }

		public override object Do(object obj)
		{						
			AITBarCodeUseSV bpObj = (AITBarCodeUseSV)obj;

			try
			{
				if (bpObj.Data == null) throw new Exception("传入参数为空");
                List<CommonArchiveDataDTOData> retlist = new List<CommonArchiveDataDTOData>();

                foreach (var item in bpObj.Data)
				{
					if (string.IsNullOrEmpty(item.BarCode)) continue;
					using(ISession session = Session.Open())
					{
						AITBarCodeUse use = AITBarCodeUse.Create();
						use.BarCode = item.BarCode;
						use.SrcDocName = item.SrcDocName;
						use.SrcDocNo = item.SrcDocNo;
						use.SrcDocLineNo = item.SrcDocLineNo;
						use.TransDirection= TransDirectionEnum.GetFromValue(item.TransDirection);
						use.Qty = item.Qty;
						session.Commit();

						CommonArchiveDataDTOData ret = new CommonArchiveDataDTOData() { ID = use.ID, Code = use.BarCode };
						retlist.Add(ret);
                    }
                }

                return ResultUtils.success(bpObj, bpObj.Data, retlist);
            }
            catch (Exception ex)
			{
                return ResultUtils.error(bpObj, bpObj.Data, ex);
            }
			

			
		}		
	}

	#endregion
	
	
}